/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aimozg.joglfw.gui;

import aimozg.joglfw.GLColor;
import aimozg.joglfw.JoglApplication;
import aimozg.joglfw.JoglApplication.GLFont;
import java.awt.Font;

/**
 *
 * @author aimozg
 */
public class GLBlock extends GLComponent{

    private GLColor bgColor = new GLColor(0,0,0,0);
    private GLColor textColor = new GLColor(1,1,1);
    private GLColor borderColor = new GLColor(1,1,1);
    private GLColor focusedBgColor = null;
    private GLColor focusedTextColor = null;
    private GLColor focusedBorderColor = null;
    private String text = "";
    private String[] lines = {};
    private static GLFont defaultFont = new GLFont(new Font("Arial", Font.PLAIN, 14));
    private GLFont font = defaultFont;

    public GLColor getBorderColor() {
        return borderColor;
    }

    public void setBorderColor(GLColor borderColor) {
        this.borderColor = borderColor;
    }

    public GLColor getFocusedBgColor() {
        return focusedBgColor;
    }

    public GLColor getFocusedBorderColor() {
        return focusedBorderColor;
    }

    public GLColor getFocusedTextColor() {
        return focusedTextColor;
    }

    public void setFocusedBgColor(GLColor focusedBgColor) {
        this.focusedBgColor = focusedBgColor;
    }

    public void setFocusedBorderColor(GLColor focusedBorderColor) {
        this.focusedBorderColor = focusedBorderColor;
    }

    public void setFocusedTextColor(GLColor focusedTextColor) {
        this.focusedTextColor = focusedTextColor;
    }

    
    
    public GLFont getFont() {
        return font;
    }

    public void setFont(GLFont font) {
        this.font = font;
    }

    

    public GLColor getBgColor() {
        return bgColor;
    }

    public String getText() {
        return text;
    }

    public GLColor getTextColor() {
        return textColor;
    }

    public void setBgColor(GLColor bgColor) {
        this.bgColor = bgColor;
    }

    public void setText(String text) {
        this.text = text;
        this.lines = text.split("\n");
    }

    public void setTextColor(GLColor textColor) {
        this.textColor = textColor;
    }

    
    
    @Override
    protected void draw() {
        GLColor bgc = (isFocused() && focusedBgColor!=null)?focusedBgColor:bgColor;
        if (bgc.alpha>0.0){
            app.drawQuads(bgc, topleft(), topright(), bottomright(), bottomleft());
        }
        GLColor txc = (isFocused() && focusedTextColor!=null)?focusedTextColor:textColor;
        if (txc.alpha>0.0){
            double fheight = font.getHeight();
            double offset = 0;
            for (String s : lines) {
                app.renderText(font,s,txc,0,offset);
                offset+=fheight;
            }
        }
        GLColor bdc = (isFocused() && focusedBorderColor!=null)?focusedBorderColor:borderColor;
        if (bdc.alpha>0.0){
            app.drawLineLoop(bdc, topleft(), topright(), bottomright(), bottomleft());
        }
    }

    public GLBlock(JoglApplication app){
        super(app);
    }

    public GLBlock(GLComponent owner) {
        super(owner);
    }

}
